<?php

namespace App\Models\Admin;
use Illuminate\Database\Eloquent\Model;

class Links extends Model{
    protected $table='links';
    protected $primaryKey='id';
    protected $guarded =[];

    //返回友情链接接地址
    public function setUrlAttribute($value){
        $this->attributes['url'] = ( strstr($value,'https') || strstr($value,'http')  ) ? $value : 'http://'.$value ;
    }

    /*@param
     * $link_sign 友情站点标识
     */
    static public function getLinks($link_sign){
        $like_site = LinkSite::where('link_sign',$link_sign)->first(['id']);
        if($like_site){
            $links = Links::where('link_site',$like_site->id)
                ->select('id','link_name','link_site','link_url','link_sort')
                ->orderBy('link_sort','asc')
                ->get();
            foreach($links as $v){
                $v->url = $v->link_url;
            }
            return $links;
        }else{
            return array();
        }
    }
}
